using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

public class LSElementStyle
{
    private const string USSPath_Dark = "Packages/com.lancerstudio.lsframework/Editor/Assets/USS/LSStyle-Dark.uss";
    private const string USSPath_Light = "Packages/com.lancerstudio.lsframework/Editor/Assets/USS/LSStyle-Dark.uss";

    private static StyleSheet s_StyleSheet_Dark = null;
    private static StyleSheet s_StyleSheet_Light = null;

    public static StyleSheet StyleSheet
    {
        get
        {
            return GetSheet();
        }
    }

    public class Classes
    {
        public static readonly string Text = "ls-text";
        public static readonly string Text_Disactive = "ls-text-disactive";

        public static readonly string Line = "ls-line";
        public static readonly string Split_Line_Horzontal = "ls-split-line-horzontal";
        public static readonly string Split_Line_Vertical = "ls-split-line-vertical";

        public static readonly string Background_Basis = "ls-background-basis";
        public static readonly string Background_Overlayer = "ls-background-overlayer";
        public static readonly string Background_Overlayer_Dark = "ls-background-overlayer-dark";

        public static readonly string Button = "ls-button";
    }

    private static StyleSheet GetSheet()
    {
        if (EditorGUIUtility.isProSkin)
        {
            if (s_StyleSheet_Dark == null)
                s_StyleSheet_Dark = AssetDatabase.LoadAssetAtPath<StyleSheet>(USSPath_Dark);

            return s_StyleSheet_Dark;
        }
        else
        {
            if (s_StyleSheet_Light == null)
                s_StyleSheet_Light = AssetDatabase.LoadAssetAtPath<StyleSheet>(USSPath_Light);

            return s_StyleSheet_Light;
        }
    }

    public static Button CreateButton(string label, Action onClick)
    {
        Button element = new Button();
        element.clicked += onClick;
        SetupStyle(element);
        return element;
    }

    public static void SetupStyle(Button element)
    {
        element.AddToClassList(Classes.Button);
    }

    public static Label CreateLabel(string label)
    {
        Label element = new Label();
        element.text = label;
        SetupStyle(element);
        return element;
    }

    public static void SetupStyle(Label element)
    {
        element.AddToClassList(Classes.Text);
    }
}

